<template>
  <basic-container>
    <dataList
      placeholder="请输入项目名称"
      :pageInfo="pager"
      :listData="tableData"
      :selectData="selectDataArr"
      searchName="formula"
      :menuList="[{receipt:'数据同步'}]"
      :filterList="filterList"
      @menu-click="handleMenuClick"
    >
      <el-table :data="tableData" align="left" @selection-change="$event => (selectDataArr = $event)">
        <el-table-column label="项目名称" prop="projectName" width="220" show-overflow-tooltip />
        <el-table-column label="项目国家编码" prop="countryCode" width="220" show-overflow-tooltip />
        <el-table-column label="立项时间(年)" prop="applyYear" width="120" />
        <el-table-column label="数据更新时间" prop="updatetime" width="160" />
        <el-table-column label="申请单位" prop="companyName" width="200" show-overflow-tooltip />
        <el-table-column label="行业归口" prop="industryCode" width="160">
          <template slot-scope="scope">{{scope.row.industryCode | dict('industry_code')}}</template>
        </el-table-column>
        <el-table-column label="总投资(元)" prop="totalInvest" width="200" :formatter="priceFormatter" />
        <el-table-column width="120" label="操作" fixed="right">
          <template slot-scope="scope">
            <el-button type="text" @click="showData(scope.row.fgProjectId)">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
    </dataList>
    <show-data ref="showData"></show-data>
  </basic-container>
</template>

<script>
import showData from '../components/show-data'
import { fetchList, updateSyncFgData } from '../api/fgprojectdata'
import BaseLoad from '@/assets/vue-mixin/BaseLoad'
export default {
  name: 'resource-manage',
  components: { showData },
  mixins: [BaseLoad],
  provide () {
    return {
      initList: this.getListData,
    };
  },
  beforeMount () {
    this.getListData();
  },
  data () {
    return {
      tableData: [],
      // 请求参数
      params: {
        current: 1,
        size: 10,
        formula: ''
      },
      // 选中的数据
      selectDataArr: [],
      // 分页
      pager: {
        total: 0, // 总页数
        current: 1, // 当前页数
        size: 10 // 每页显示多少条
      },
      // 页面loading
      loading: false,
      filterList: [
        { label: '项目国家编码', inputType: 'input', name: 'countryCode' },
        { label: '立项时间开始区间', inputType: 'year', name: 'startApplyYear' },
        { label: '立项时间结束区间', inputType: 'year', name: 'endApplyYear' },
        { label: '更新时间开始区间', inputType: 'date', name: 'startTime' },
        { label: '更新时间结束区间', inputType: 'date', name: 'endTime' },
      ],
    }
  },
  methods: {
    getListData (params = {}) {
      this.loading = true
      let requestData = { ...this.params, ...params }
      fetchList(requestData).then(res => {
        const { current, size, total, records } = res.data.data
        this.tableData = records
        this.params = requestData
        this.pager = { total, current, size }
      }).finally(() => {
        this.loading = false
      })
    },
    showData (item) {
      this.$refs.showData.show(item)
    },
    syncFgData () {
      this.loadAction('请稍等...')
      updateSyncFgData().then((res) => {
        this.$message.success(res.data.msg);
        this.loadClose();
        this.getListData();
      }).finally(() => {
        this.loadClose();
      })
    },
    // 菜单点击监听
    handleMenuClick (type) {
      switch (type) {
        case 'receipt':
          this.syncFgData();
          break;
        default:
          this.$message(type)
          break;
      }
    },
  }
}
</script>
<style scoped lang="scss">
</style>

